package cn.jichangxiu.ucenter.mapper;

import cn.jichangxiu.common.ucenter.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface RoleMapper extends JpaRepository<Role, String>, JpaSpecificationExecutor<Role> {

    @Query(nativeQuery = true , value = "SELECT a.* FROM prey_role a , prey_user_role b WHERE a.id = b.role_id AND b.user_id = ?")
    public List<Role> findRolesByUserId(String userId);

    @Query(nativeQuery = true , value = "SELECT * FROM prey_role a WHERE a.id in (:roleIds)")
    public List<Role> findRolesByRoleIds(@Param("roleIds") List<String> roleIds);

}
